package com.hmall.api.fallback;

import com.hmall.api.client.ItemClient;
import com.hmall.api.dto.ItemDTO;
import com.hmall.api.dto.OrderDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

@Component
@Slf4j
public class ItemClientFallbackFactory implements FallbackFactory<ItemClient> {
    @Override
    public ItemClient create(Throwable cause) {
        return new ItemClient() {
            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
                log.info("queryItemByIds降级处理");
                return List.of();
            }

            @Override
            public void deductStock(Collection<OrderDetailDTO> items) {
                log.info("deductStock降级处理");
            }

            @Override
            public ItemDTO queryItemById(Long id) {
                log.info("queryItemById降级处理");
                return null;
            }

            @Override
            public void updateItem(ItemDTO item) {
                log.info("updateItem降级处理");
            }

            @Override
            public void batchRestoreStock(List<OrderDetailDTO> orderDetailDTOS) {
                log.info("batchRestoreStock降级处理");
            }

            @Override
            public List<ItemDTO> getEsList(Integer page, Integer size) {
                return List.of();
            }
        };
    }
}
